package com.nulldev.util.concurrency.threadIt.v4.emapi.testing;

import java.util.concurrent.LinkedBlockingQueue;

import com.nulldev.util.JVM.JVM;
import com.nulldev.util.concurrency.threadIt.v4.emapi.ExecutorManager;
import com.nulldev.util.concurrency.threadIt.v4.emapi.uft.Executable;

public class DeadlockTests {

	public static void main(String[] args) {
		final LinkedBlockingQueue<Executable<Object>> o = new LinkedBlockingQueue<Executable<Object>>();
		final int AMOUNT_OF_WORKERS = 96;
		for (int i = 0; i < AMOUNT_OF_WORKERS; i++) {
			final int f = i;
			try {
				o.put(ExecutorManager.globalSubmit(() -> {
					return f * AMOUNT_OF_WORKERS;
				}));
			} catch (InterruptedException e) {
				JVM.errorln(e);
			}
		}
		JVM.println(":: Awaiting...");
		ExecutorManager.get().awaitQueue(o);
		JVM.println(":: Finished.");
		JVM.println(":: Printing values.");
		Executable<Object> obj;
		while ((obj = o.poll()) != null) {
			JVM.println(obj.result());
		}
	}
}
